package com.yhy.server.controller;

import com.yhy.server.service.CommentService;
import com.yhy.server.service.MovementsMQService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @Autowired
    private MovementsMQService movementsMQService;

    @GetMapping
    public ResponseEntity findAllComments(@RequestParam(defaultValue = "1") Integer page,
                                          @RequestParam(defaultValue = "10") Integer pagesize,
                                          String movementId){
        return commentService.findAllComments(page,pagesize,movementId);
    }

    @PostMapping
    public ResponseEntity commitComment(@RequestBody Map map){
        String publishId = (String) map.get("movementId");
        String content = (String) map.get("comment");
        movementsMQService.sendMsg(publishId,4);//type 4 评论
        return commentService.commitComment(publishId,content);
    }

    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String publishId){
        return commentService.commentLike(publishId);
    }
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id") String publishId){
        return commentService.commentDislike(publishId);
    }
}
